package oss.controller;

import config.Interceptor.PassToken;
import controller.BaseController;

import details.mapper.WxuserdetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import oss.policy.Wxbottleurl;
import oss.service.impl.Wxbottleurlserviceimpl;
import utils.CommonRetumType;
import wx.mapper.WxuserMapper;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

@RestController
@RequestMapping("/wxbottleurl")
public class WxbottleurlController{
    @Autowired
    Wxbottleurlserviceimpl wxbottleurlserviceimpl;

    @Autowired
    WxuserMapper wxuserMapper;


    @GetMapping("/create")
    @PassToken
    public CommonRetumType insert(@RequestParam("openId") String openid, Wxbottleurl wxbottleurl)
    {
        wxbottleurl.setOpenid(openid);
        if (wxbottleurlserviceimpl.selectByPrimaryKey(wxbottleurl.getOpenid())==null){
            return CommonRetumType.create(wxbottleurlserviceimpl.insertSelective(wxbottleurl),"卡片创建成功");
        }else {
            return CommonRetumType.create(wxbottleurlserviceimpl.updateByPrimaryKeySelective(wxbottleurl),"卡片信息更新成功");
        }
    }

    @GetMapping("/index")
    @PassToken
    public CommonRetumType index(@RequestParam("usersex") String usersex,
                                 @RequestParam("openId") String openid)
    {
        List<Wxbottleurl> Wx = wxbottleurlserviceimpl.selectindex(usersex,openid);
        for (Wxbottleurl w:Wx) {
            w.setWxuser(wxuserMapper.selectByPrimaryKey(w.getOpenid()));
        }
        return  CommonRetumType.create(Wx,"列表查询成功");
    }

    @GetMapping("/read")
    @PassToken
    public CommonRetumType read(@RequestParam("openId") String openid)
    {
        return  CommonRetumType.create(wxbottleurlserviceimpl.selectByPrimaryKey(openid),"个人卡片查询成功");
    }
}
